package com.gmail.dmitryustimov.ms.java7.mediator.mod.work.testperf;

import com.gmail.dmitryustimov.ms.java7.mediator.mod.work.demo.col10event10.*;

public class TestPerfCol10Event10 {

    private static final int NUM_UPDATES = 100000;
    private static final int NUM_WARM_UP = 3;
    private static final int NUM_TESTS = 10;

    private static final String MESSAGE = "mediator_classic, 10 colleagues, 10 event type, took: ";

    public static void main(String[] args) {

        //warm up
        for (int i = 0; i < NUM_WARM_UP; i++) {
            test();
        }

        //tests
        long time = 0;
        for (int j = 0; j < NUM_TESTS; j++) {
            time += test();
        }
        System.out.println("final - " + MESSAGE + time/NUM_TESTS + "ns (" + (time/NUM_TESTS)/1000000 + "ms)");
    }

    private static long test() {
        Mediator mediator = new Mediator("Mediator");

        AbstractColleague c1 = new ConcreteColleague1("ConcreteColleague1", mediator);
        AbstractColleague c2 = new ConcreteColleague2("ConcreteColleague2", mediator);
        AbstractColleague c3 = new ConcreteColleague3("ConcreteColleague3", mediator);
        AbstractColleague c4 = new ConcreteColleague4("ConcreteColleague4", mediator);
        AbstractColleague c5 = new ConcreteColleague5("ConcreteColleague5", mediator);
        AbstractColleague c6 = new ConcreteColleague6("ConcreteColleague6", mediator);
        AbstractColleague c7 = new ConcreteColleague7("ConcreteColleague7", mediator);
        AbstractColleague c8 = new ConcreteColleague8("ConcreteColleague8", mediator);
        AbstractColleague c9 = new ConcreteColleague9("ConcreteColleague9", mediator);
        AbstractColleague c10 = new ConcreteColleague10("ConcreteColleague10", mediator);

        mediator.addColleague(c1);
        mediator.addColleague(c2);
        mediator.addColleague(c3);
        mediator.addColleague(c4);
        mediator.addColleague(c5);
        mediator.addColleague(c6);
        mediator.addColleague(c7);
        mediator.addColleague(c8);
        mediator.addColleague(c9);
        mediator.addColleague(c10);

        long startTime = System.nanoTime();

        for (long j = 0; j < NUM_UPDATES; j++) {
            c1.makeEvent();
            c2.makeEvent();
            c3.makeEvent();
            c4.makeEvent();
            c5.makeEvent();
            c6.makeEvent();
            c7.makeEvent();
            c8.makeEvent();
            c9.makeEvent();
            c10.makeEvent();
        }

        long estimatedTime = System.nanoTime() - startTime;
        System.out.println(MESSAGE + estimatedTime + "ns");
        return estimatedTime;
    }
}
